//
//  SLAttentionRowCell.m
//  StarLight
//
//  Created by apple on 16/8/12.
//  Copyright © 2016年 Duke.Wu. All rights reserved.
//

#import "SLAttentionRowCell.h"

@interface SLAttentionRowCell ()

@property (nonatomic ,strong) UIImageView *headImg;
@property (nonatomic ,strong) UILabel *nickName;
@property (nonatomic ,strong) UILabel *VIP;
@property (nonatomic ,strong) UIImageView *VIPImg;
@property (nonatomic ,strong) UILabel *otherName;
@property (nonatomic ,strong) UIView *bgView;
@property (nonatomic ,strong) UILabel *numOrder;
@property (nonatomic ,strong) UILabel *info;
@property (nonatomic ,strong) UIImageView *inImg;
@property (nonatomic ,strong) UILabel *vipLv;

@end

@implementation SLAttentionRowCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addUI];
    }
    return self;
}
- (void)configFriendListCellWithModel:(SLFriendModel *)model{
    
    self.friendModel = model;
    [self hiddenWithType:model.type];

//    NSString *zero = model.kNum == 0 ? @"" : [NSString stringWithFormat:@" 空船:%ld ",(long)model.kNum];
//    NSString *half = model.bNum == 0 ? @"" : [NSString stringWithFormat:@" 半船:%ld ",(long)model.bNum];
//    NSString *full = model.mNum == 0 ? @"" : [NSString stringWithFormat:@" 满船:%ld ",(long)model.mNum];
//    NSString *reserve = model.yNum ==0 ? @"" : [NSString stringWithFormat:@" 预定:%ld",(long)model.yNum];

//    self.zeroCountLB.text = zero;
//    self.halfCountLB.text = half;
//    self.fullCount.text = full;
//    self.reserveCountLB.text = reserve;
    if (model.goodsNum != 0) {
        self.numOrder.hidden = NO;
        self.bgView.hidden = NO;
        self.numOrder.text = [NSString stringWithFormat:@" 近期发货:%ld单",(long)model.goodsNum];
        CGFloat numOrderW = [self.numOrder sizeThatFits:CGSizeMake(MAXFLOAT, 12)].width;
        [self.bgView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(numOrderW + 22);
        }];
    }else{
        self.numOrder.hidden = YES;
        self.bgView.hidden = YES;
    }
    
    [self.headImg sd_setImageWithURL:[NSURL URLWithString:model.headPhoto] placeholderImage:[UIImage imageNamed:@"head"]];
    self.otherName.text = model.name;

    if (model.role < 1) {
        self.VIP.hidden = YES;
        self.vipLv.hidden = YES;
    }else{
        self.VIP.hidden = NO;
        self.vipLv.hidden = NO;
        self.vipLv.text =[NSString stringWithFormat:@"%ld",(long)model.role];
    }
    
//    if (model.phone) {
//        self.phoneLB.text = model.phone;
//    }
    
}

- (void)hiddenWithType:(NSInteger)type{
//    if (type == 0 ) {
//        self.nearDateLB.hidden = YES;
//        self.zeroCountLB.hidden = NO;
//        self.halfCountLB.hidden = NO;
//        self.fullCount.hidden = NO;
//        self.reserveCountLB.hidden = NO;
//        self.friendTypeLb.text = @"船主";
//    }else{
//        self.friendTypeLb.text = @"货主";
//        self.zeroCountLB.hidden = YES;
//        self.halfCountLB.hidden = YES;
//        self.fullCount.hidden = YES;
//        self.reserveCountLB.hidden = YES;
//        self.nearDateLB.hidden = NO;
//    }
    
}

- (void)addUI{
    [self addSubview:self.headImg];
    [self addSubview:self.nickName];
    [self addSubview:self.VIP];
    [self addSubview:self.VIPImg];
    [self.VIPImg addSubview:self.vipLv];
    [self addSubview:self.otherName];
    [self addSubview:self.bgView];
    [self.bgView addSubview:self.numOrder];
    [self addSubview:self.info];
    [self addSubview:self.inImg];
    
    [self.headImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self).with.offset(16);
        make.height.width.mas_equalTo(61);
    }];
    [self.nickName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headImg.mas_right).with.offset(10);
        make.top.equalTo(self).with.offset(12);
    }];
    [self.VIP mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nickName.mas_right).with.offset(10);
        make.centerY.equalTo(self.nickName);
    }];
    [self.VIPImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.nickName);
        make.left.equalTo(self.VIP.mas_right).with.offset(3);
    }];
    [self.vipLv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.VIPImg);
        make.centerY.equalTo(self.VIPImg);
    }];
    [self.otherName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).with.offset(-18);
        make.centerY.equalTo(self.nickName);
    }];
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nickName);
        make.bottom.equalTo(self.headImg);
        make.height.mas_equalTo(21);
        make.width.mas_equalTo(101);
    }];
    [self.numOrder mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.centerX.equalTo(self.bgView);
    }];
    [self.inImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.otherName);
        make.centerY.equalTo(self.bgView);
    }];
    [self.info mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.inImg);
        make.right.equalTo(self.inImg.mas_left).with.offset(-14);
    }];
}

- (UIImageView *)headImg{
    if (!_headImg) {
        _headImg = [UIImageView new];
        _headImg.backgroundColor = [UIColor grayColor];
    }
    return _headImg;
}
- (UILabel *)nickName{
    if (!_nickName) {
        _nickName = [UILabel new];
        _nickName.text = @"货主";
        _nickName.font = sFont(14);
        _nickName.textColor = RGBCOLOR(0, 0, 0);
    }
    return _nickName;
}
- (UILabel *)VIP{
    if (!_VIP) {
        _VIP = [UILabel new];
        _VIP.text = @"VIP";
        _VIP.font = bFont(12);
        _VIP.textColor = RGBCOLOR(238, 85, 85);
    }
    return _VIP;
}
- (UIImageView *)VIPImg{
    if (!_VIPImg) {
        _VIPImg = [UIImageView new];
        _VIPImg.image = IMG(@"lv");
    }
    return _VIPImg;
}
- (UILabel *)vipLv{
    if (!_vipLv) {
        _vipLv = [UILabel new];
        _vipLv.textColor = RGBCOLOR(188,141,13);
        _vipLv.font = bFont(10);
    }
    return _vipLv;
}
- (UILabel *)otherName{
    if (!_otherName) {
        _otherName = [UILabel new];
        _otherName.text = @"货主张三";
        _otherName.font = sFont(14);
        _otherName.textColor = RGBCOLOR(0, 0, 0);
    }
    return _otherName;
}
- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [UIView new];
        _bgView.backgroundColor = RGBCOLOR(235, 113, 38);
    }
    return _bgView;
}
- (UILabel *)numOrder{
    if (!_numOrder) {
        _numOrder = [UILabel new];
        _numOrder.text = @"近期发货：2单";
        _numOrder.textAlignment = NSTextAlignmentCenter;
        _numOrder.font = bFont(12);
        _numOrder.textColor = RGBCOLOR(255, 255, 255);
    }
    return _numOrder;
}
- (UILabel *)info{
    if (!_info) {
        _info = [UILabel new];
        _info.text = @"详情";
        _info.font = sFont(12);
        _info.textColor = RGBCOLOR(153, 153, 153);
    }
    return _info;
}
- (UIImageView *)inImg{
    if (!_inImg) {
        _inImg = [UIImageView new];
        _inImg.image = IMG(@"ic_arrow_gray");
    }
    return _inImg;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
